package cn.circle.system.dao.impl;


import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import cn.circle.commom.dao.impl.BaseDaoImpl;
import cn.circle.system.dao.ICommodityInfoDao;
import cn.circle.system.model.CommodityInfo;
import cn.circle.system.model.SysCustomer;
import cn.circle.system.model.SysDepartment;
@Repository
public class CommodityInfoDaoImpl extends BaseDaoImpl<CommodityInfo> implements ICommodityInfoDao{

	@Override
	public boolean deleteAll(String ids) {
		// TODO Auto-generated method stub
		String hql = "delete CommodityInfo s where s.commodityId in ("+ids+") ";
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql);
		//query.setString(0, ids);
		return (query.executeUpdate() > 0);
		
	}
	@Override
	public boolean removeAll(String ids) {
		String hql = "update CommodityInfo s set s.status = 0 where s.commodityId in ("+ids+") ";
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql);
		return (query.executeUpdate() > 0);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CommodityInfo> getDep() {
		String hql = " from CommodityInfo ";
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql);
		return  query.list();
	}

	@Override
	public boolean updateAll(CommodityInfo c) {
      System.out.println("lhsafhs"+c.getNames());
		StringBuffer hql = new StringBuffer(
				"update CommodityInfo s set ");
		
		//拼接修改条件
		if(c.getNames()!= null && !"".equals(c.getNames())){
			hql.append("  s.names = '"+c.getNames()+"' ");
		}
//		if(c.getLoginName() != null && !"".equals(c.getLoginName())){
//			hql.append(" , s.loginName = '"+c.getLoginName()+"' ");
//		}
//
//		if(c.getPassWord() != null && !"".equals(c.getPassWord())){
//			hql.append(" , s.passWord = '"+c.getPassWord()+"' ");
//		}
	/*	if(c.getSysDepartment().getDepId() != null && !"".equals(c.getSysDepartment().getDepId())){
			hql.append(" , s.sysDepartment.depId="+c.getSysDepartment().getDepId());
		}*/
//		if(c.getCommodityCategory().getCategoryId() != null && !"".equals(c.getCommodityCategory().getCategoryId())){
//			hql.append(" , s.commodityCategory.categoryId="+c.getCommodityCategory().getCategoryId());
//		}
		if(c.getCreateUserId() != null && !"".equals(c.getCreateUserId())){
			hql.append(" , s.createUserId ="+c.getCreateUserId());
		}
		
		if(c.getOrderCount() != null ){
			hql.append(" , s.orderCount ="+c.getOrderCount());
		}
		if(c.getPhoto() != null && !"".equals(c.getPhoto())){
			hql.append(" , s.photo = '"+c.getPhoto()+"' ");
		}
		if(c.getPrice() != null && !"".equals(c.getPrice())){
			hql.append(" , s.price = "+c.getPrice());
		}
		if(c.getNativePrice()!= null && !"".equals(c.getNativePrice())){
			hql.append(" , s.nativePrice = "+c.getNativePrice());
		}
		if(c.getStatus() != null && !"".equals(c.getStatus())){
			hql.append(" , s.status = "+c.getStatus());
		}
		if(c.getSummary() != null && !"".equals(c.getSummary() )){
			hql.append(" , s.summary = '"+c.getSummary() +"'");
		}
		if(c.getUpdateTime() != null && !"".equals(c.getUpdateTime() )){
			hql.append(" , s.updatetime ='"+c.getUpdateTime()+"'");
		}
		if(c.getUpdateUserId() != null && !"".equals(c.getUpdateUserId())){
			hql.append(" , s.updateUserId = "+c.getUpdateUserId());
		}
		if(c.getViewCount()!= null && !"".equals(c.getViewCount())){
			hql.append(" , s.viewCount ="+c.getViewCount());
		}
		if(c.getCreateTime() != null ){
			hql.append(" , s.createTime ='"+c.getCreateTime()+"'");
		}
		if(c.getCommodityCategory().getCategoryId() != null && !"".equals(c.getCommodityCategory().getCategoryId())){
			hql.append(" , s.commodityCategory.categoryId = "+c.getCommodityCategory().getCategoryId()+ " ");
		}
		if(c.getNumber() != null && !"".equals(c.getNumber())){
			hql.append(" , s.number = "+c.getNumber());
		}
		

		hql.append(" where s.commodityId ="+c.getCommodityId());
		Query query = super.sessionFactory.getCurrentSession().createQuery(hql.toString());
		return (query.executeUpdate() > 0);
	}

	
	
	

}
